package com.springboot.killingsystem.result;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class CodeMsg {

    // 通用异常 5001XX
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "error");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常：%s");

    // 登录模块 5002XX
    public static CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session不存在或者已经失效");
    public static CodeMsg PASSWORD_EMP = new CodeMsg(500211, "密码不能为空");
    public static CodeMsg MOBILE_EMP = new CodeMsg(500212, "手机号不能为空");
    public static CodeMsg MOBILE_INVALID = new CodeMsg(500213, "手机号格式错误");
    public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");

    // 商品模块 5003XX


    // 订单模块 5004XX
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500410, "订单不存在");

    // 秒杀模块 5005XX
    public static CodeMsg ZERO_STOCK = new CodeMsg(500500, "商品库存不足！");
    public static CodeMsg REPEAT_SECOND_KILLING = new CodeMsg(500501, "已经秒杀过商品");
    public static CodeMsg SECOND_KILLING_OVER = new CodeMsg(500502, "秒杀活动已结束");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500503, "请求非法");
    public static CodeMsg REQUEST_FREQUENCY = new CodeMsg(500504, "请求过于频繁");


    private int code;
    private String msg;

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

}
